/********************************************************************
	created:	2008/09/29
	created:	29:9:2008   17:30
	filename: 	h:\SimoneEngine\qianye\src\qylib\filesys\qyFileSystem.h
	author:		Xiong Jiayu
	copyright:  
	purpose:	
*********************************************************************/
#pragma once

#ifndef __QYFILESYSTEM_H__
#define __QYFILESYSTEM_H__

#include "../common/qySingleton.h"
#include "../memsys/qyString.h"
#include "../memsys/qyArray.h"
#include "../memsys/qyAutoPtr.h"
#include "qyFile.h"
#include "qyZipPackage.h"

class qyFileFilter;
class qyZipPackage;

void		qyFormatPath( const qyString &orig, qyString &formated );
qyString	qyFormatPath( const qyString &orig );

/*
===========================================
class qyFileSystem
===========================================
*/
class qyFileSystem : public qySingleton< qyFileSystem >
{
	typedef	qyArray<qyString>		PathList;
	typedef qyArray<qyZipPackage*>	PackageList;
public:
							qyFileSystem();
							~qyFileSystem();

	//-----------------------------------------------------------------------
	//----	Path	-------------------------------------------------------------------
	//-----------------------------------------------------------------------
	//  @{
	void					AddRootPath( const qyString &path );
	void					RemoveRootPath( const qyString &path );
	void					RemoveAllRootPath( void );
	const qyString &		GetRootPath( void ) const;
	//  @}

	//-----------------------------------------------------------------------
	//----	Package	-------------------------------------------------------------------
	//-----------------------------------------------------------------------
	//  @{
	qyZipPackage *			AddPackage( const qyString &name );
	qyZipPackage *			GetPackage( const qyString &name );
	bool					RemovePackage( const qyString &name );
	void					RemoveAllPackage();
	//  @}

	qyFile *				OpenReadFile( const qyString &filename, bool bUsingAbsolutePath = false );

	//-----------------------------------------------------------------------
	//----	Path Utilities	-------------------------------------------------------------------
	//-----------------------------------------------------------------------
	//  @{
	qyString 				GetRelatedPathFromFullPath( const qyString &path );
	qyString				GetFullPathFromRelatedPath( const qyString &path );
	//  @}

protected:
	bool					RequireFile( qyFile *file, const qyString &rootPath );
protected:
	PathList				m_paths;
	PackageList				m_packages;
	qyFileFilter			*m_commonFilter;
	qyFileFilter			*m_pckFilter;
};

#endif
